package unmsm.eapisw.taller.srh_persistencia.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;

import unmsm.eapisw.taller.srh_persistencia.dao.IAdministradorDAO;
import unmsm.eapisw.taller.srh_persistencia.modelo.Administrador;

public class AdministradorDAO implements IAdministradorDAO {
	private SessionFactory sessionFactory;

	/**
	 * Get Hibernate Session Factory
	 * 
	 * @return SessionFactory - Hibernate Session Factory
	 */
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/**
	 * Set Hibernate Session Factory
	 * 
	 * @param SessionFactory
	 *            - Hibernate Session Factory
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public void addAdministrador(Administrador adm) {

	}

	public void updateAdministrador(Administrador adm) {

	}

	public void deleteAdministrador(Administrador adm) {
		
	}

	public Administrador getAdministradorById(String usuario) {
		
		List list = getSessionFactory().getCurrentSession().createQuery("from Administrador where usuario = ?").setParameter(0, usuario).list();
		
		if(list==null || list.isEmpty()){
			
			return null;
		}
		return (Administrador) list.get(0);

	}

	public List<Administrador> getAdministrador() {
		List list = getSessionFactory().getCurrentSession()
				.createQuery("from Administrador").list();
		return list;
	}

}
